package com.atguigu.controller;

import com.atguigu.entity.Dict;
import com.atguigu.result.Result;
import com.atguigu.service.DictService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/dict")
public class DictController {
        @DubboReference
    private DictService dictService;
        @RequestMapping
        public String index(){
            return "dict/index";
        }
        /*接收父id根据父Id 查询所有的子数据做异步响应的处理器*/
        @GetMapping(value = "/findZnodes")
        @ResponseBody
        public Result findByParentId(@RequestParam(value = "id", defaultValue = "0") Long id) {
            List<Map<String,Object>> zNodes = dictService.findZondes(id);
            return Result.ok(zNodes);
        }

        @GetMapping("/findListByParentId/{parentId}")
        @ResponseBody
        public Result<List<Dict>> findListByParentId(@PathVariable Long parentId){
            List<Dict> list = dictService.findListByParentId(parentId);
            return Result.ok(list);
        }
        @GetMapping("/findListByDictCode/{dictCode}")
        @ResponseBody
        public Result<List<Dict>> findListByDictCode(@PathVariable String dictCode){
            List<Dict> list = dictService.findListByDictCode(dictCode);
            return Result.ok(list);
        }

}
